<template>
  <div
    class="site-wrapper"
    :class="{ 'site-sidebar--fold': sidebarFold }"
    v-loading.fullscreen.lock="loading"
    element-loading-text="拼命加载中">
    <template v-if="!loading">
      <main-navbar />
      <main-sidebar />
      <div :style="{ 'height': documentClientHeight + 'px' }" class="box"></div>
      <div class="site-content__wrapper" :style="{ 'min-height': documentClientHeight + 'px' }">
        <main-content v-if="!$store.state.common.contentIsNeedRefresh" />
      </div>
    </template>
  </div>
</template>

<script>
  import MainNavbar from './main-navbar'
  import MainSidebar from './main-sidebar'
  import MainContent from './main-content'
  import Watermark from '../utils/watermark'
  export default {
    provide () {
      return {
        // 刷新
        refresh () {
          this.$store.commit('common/updateContentIsNeedRefresh', true)
          this.$nextTick(() => {
            this.$store.commit('common/updateContentIsNeedRefresh', false)
          })
        }
      }
    },
    data () {
      return {
        loading: true
      }
    },
    components: {
      MainNavbar,
      MainSidebar,
      MainContent
    },
    computed: {
      documentClientHeight: {
        get () { return this.$store.state.common.documentClientHeight },
        set (val) { this.$store.commit('common/updateDocumentClientHeight', val) }
      },
      sidebarFold: {
        get () { return this.$store.state.common.sidebarFold }
      },
      userId: {
        get () { return this.$store.state.user.id },
        set (val) { this.$store.commit('user/updateId', val) }
      },
      userName: {
        get () { return this.$store.state.user.name },
        set (val) { this.$store.commit('user/updateName', val) }
      },
      staffAccount: {
        get () { return this.$store.state.user.staffAccount },
        set (val) { this.$store.commit('user/updateStaffAccount', val) }
      },
      cityCode: {
        get () { return this.$store.state.user.cityId },
        set (val) { this.$store.commit('user/updateCityCode', val) }
      }
    },
    created () {
      this.getUserInfo()
      this.fetchLableList()
      this.fetchUrlList()
      this.fetchDuLableList()
      this.fetchTitleList()
      this.fetchSelectData()
      this.getCityList()
      // this.fetchCycleData()
    },
    mounted () {
      this.resetDocumentClientHeight()
    },
    methods: {
      // 获取当前时间
      fetchNowDate () {
        let date = new Date()
        let house = date.getHours() >= 10 ? date.getHours() : '0' + date.getHours()
        let minutes = date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes()
        let seconds = date.getSeconds() >= 10 ? date.getSeconds() : '0' + date.getSeconds()
        return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}  ${house}:${minutes}:${seconds}`
      },
      // 获取地市数据
      getCityList () {
          this.$http({
          url: this.$http.adornUrl('/syscitydata/cityList'),
          method: 'get',
          params: this.$http.adornParams({
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            console.log('city', data)
            this.$store.commit('common/updateCityList', data.list)
            // this.cityList = data.page.list
          }
        })
      },
      // 查询字典表
      // fetchCycleData () {
      //   this.$http({
      //     url: this.$http.adornUrl('/sysdictdata/list'),
      //     method: 'get',
      //     params: this.$http.adornParams({
      //       dictType: 'send_time_type'
      //     })
      //   }).then(({ data }) => {
      //     if (data && data.code === 0) {
      //       this.$store.commit('type/updateCycle', data.page.list)
      //     }
      //   })
      // },
      // 获取标签下拉列表
      fetchLableList () {
        this.$http({
          url: this.$http.adornUrl('/sysdictdata/list'),
          method: 'get',
          params: this.$http.adornParams({
            dictType: 'user_tag'
          })
        }).then(({ data }) => {
          console.log(data)
          if (data && data.code === 0) {
            this.$store.commit('type/updateUserTag', data.page.list)
          }
        })
      },
      fetchUrlList () {
        this.$http({
          url: this.$http.adornUrl('sysdictdata/list'),
          method: 'get',
          params: this.$http.adornParams({
            dictType: 'secretary_send_url',
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$store.commit('type/updateSecretarySendUrl', data.page.list)
          }
        })
      },
      fetchDuLableList () {
        this.$http({
          url: this.$http.adornUrl('sysdictdata/list'),
          method: 'get',
          params: this.$http.adornParams({
            dictType: 'du_user_tag'
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
           this.$store.commit('type/updateDuUserTag', data.page.list)
          }
        })
      },
      fetchTitleList () {
        this.$http({
          url: this.$http.adornUrl('/sysdictdata/list'),
          method: 'get',
          params: this.$http.adornParams({
            dictType: 'du_text'
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$store.commit('type/updateDuText', data.page.list)
          }
        })
      },
      fetchSelectData () {
        this.$http({
          url: this.$http.adornUrl('sysdictdata/list'),
          method: 'get',
          params: this.$http.adornParams({
          dictType: 'send_type'
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$store.commit('type/updateSenType', data.page.list)
          }
        })
      },
      // 重置窗口可视高度
      resetDocumentClientHeight () {
        this.documentClientHeight = document.documentElement['clientHeight']
        window.onresize = () => {
          this.documentClientHeight = document.documentElement['clientHeight']
        }
      },
      // 获取当前管理员信息
      getUserInfo () {
        this.$http({
          url: this.$http.adornUrl('/sys/user/info'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            console.log('info', data)
            this.loading = false
            this.userId = data.user.userId
            this.userName = data.user.username
            this.staffAccount = data.user.staffAccount
            this.cityCode = data.user.latnId
            // 加水印
            let str = `${this.userName} ${this.staffAccount} ${data.user.companyName} ${data.user.orgName} ${this.fetchNowDate()}`
            Watermark.set(str)
            console.log("data.user===",data.user);
          }
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
.box{
  width: 100%;
  background: url('~@/assets/img/h_bg.png') no-repeat;
  background-size: 100% 100%;
  position: fixed;
  padding-top: 50px;
  margin-left: 230px;
}
</style>

